var loadSearchList = function(){
	$('#searchList').show();
};
//自适应高
var autoHeight = function(){
	var height = $(this).height() - 183;
	if(height < 250){
		height = 250;
	}
	$('#frameBox').height(height);
};
$(function(){
	var iframe = document.getElementById("mainIframe");
    iframe.onload = iframe.onreadystatechange = function iframeload(){
        if(!iframe.readyState || iframe.readyState == "complete"){
             $('#loadmenu,#mainTip').hide();
        }
    };
    $(window).resize(autoHeight);
    autoHeight.call(window);
	//帐户信息、关于
    $('#accountinfo,#about').mouseenter(function(){
    	$(this).children('.popPanel').show();
    }).mouseleave(function(){
    	$(this).children('.popPanel').hide();
    });
    //搜索
    $('#search-bt').click(loadSearchList);
    //主菜单
    $('#menu-ul .menu-group').click(function(){
    	$(this).parent().siblings().children('.sub').slideUp();
    	$(this).next(".sub").slideDown();
    });
    $('#menu-ul .sub li').hover(function(){
    	$(this).addClass('hover');
    },function(){
    	$(this).removeClass('hover');
    }).click(function(){
    	var mainTip = $('#mainTip');
    	if(mainTip.is(":hidden")){
    		var self = $(this);
    		$('#nav').html('<span>'+self.closest('.sub').prev().text()+'</span><b></b><span>'+self.children().text()+'</span>');
    		mainTip.show();
    		$('.selected',self.closest('#menu-ul')).removeClass('selected');
    		self.addClass('selected');
    		var url = self.attr('url');
    		url += '?random='+Math.random();
    		$('#mainIframe').attr('src',url);
    	}
    });
    $('#message a').click(function(){
    	alert('打开相应页面:'+$(this).html());
    });
    //默认选中第一个
    $('#menu-ul .menu-group:first,#menu-ul .sub li:first').click();
    //菜单折叠/展开
    $('#menu-close').click(function(){
    	$('#menu').hide(300);
    	$('#menu-closed').show(300);
    	$("#main").animate({'margin-left':'46px'},300);
    });
    $('#menu-open').click(function(){
    	$('#menu').show(300);
    	$('#menu-closed').hide(300);
    	$("#main").animate({'margin-left':'234px'},300);
    });
    //退出
    $('#exit').click(function(){
    	$.messager.confirm('提示','您确定要退出系统吗？',function(r){
    		if(r){
    			$.ajax({
    				url:'account/logout.jx',
    				success:function(obj){
    					$.successParser(obj);
    					if(obj.success){
    						location.reload();
    					}
    				}
    			});
    		}
    	});
    });
    //修改密码
    $('#updatePass').click(function(){
    	var box = $("#updpassWin");
    	box.show();
    	box.dialog({
    		href:'account/updpass.html',
    		width:400,
    		modal:true,
    		onLoad:function(){
    			$("#updpassWin").dialog('center');
    		},
    		buttons: [{
    			text:'确定',
    			iconCls:'icon-ok',
    			handler:function(){
    				$('#updpassForm').form('submit', {
    			        url:'account/update-pass.jx',
    			        dataType:'json',
    			        onSubmit:function(param){
    			            if(!$(this).form('validate')){
    			                return false;
    			            }
    			            $.messager.progress();
    			        },
    			        success:function(obj){
    			        	obj = $.parseJSON(obj);
    			        	$.successParser(obj);
    			            if(obj.success){
    			            	$('#updpassWin').window('close');
    			            	$.messager.alert('提示','密码修改成功，请重新登录！','info',function(){
                                    location.reload();
                                });
    			            }
    			            $.messager.progress('close');
    			        },
    			        onLoadError:function(){
    			            $.messager.progress('close');
    			        }
    			    });
    			}
    		},{
    			text:'关闭',
    			handler:function(){
    				$("#updpassWin").dialog('close');
    			}
    		}]
    	});
    });
});